import {mapMutations} from 'vuex'
// 引入antv组件
import F2 from '@/uni_modules/lime-f2/components/l-f2/f2-all.min.js';
export default {
    ...mapMutations([
		'upUserInfo'
    ]),
	
	toSend(){
		this.$refs.sendPopup.open()
	},
	closeSendPopup(){
		this.$refs.sendPopup.close()
	},
	toSearch(){
		uni.navigateTo({
			url: '/pages/index/search'
		})
		// this.$toast.msg("暂未开放！", {
		// 	icon: 1
		// })
	},
	//发表想法
	submit(){
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/publishThought',
			params: that.formData,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg('发布成功', {
					    icon: 1
					})
					that.closeSendPopup()
				}else{
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			
			}
		})
	},
	//获取今日今指数图表数据
	getTodayIndex(id){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getTodayIndex',
			params: {
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.baseData = res.data
					// 班组考勤==========================================================================
					this.$refs.todayIndex.init(config => {
						config.padding = [ 'auto', 20, 'auto', 'auto']
						const chart = new F2.Chart(config);
						chart.source(that.baseData, {
							// value:{//y轴的数值间隔
							// 	tickCount:30
							// }
						});
						chart
							.interval()
						.position('date*pointTotal')
						.color('date*pointTotal', [ 'rgba(252, 67, 142, 1)', 'rgba(35, 193, 101, 1)','rgba(255, 150, 43, 1)','rgba(92, 159, 254, 1)' ])
						 .style('pointTotal', {
						     radius: function radius(val) {
						       return val > 0 ? [ 2, 2, 0, 0 ] : [ 0, 0, 2, 2 ];
						     }
						   })
						.adjust('stack');//不分组
						chart.axis('date', {
							label:{
								fill: '#666666',
								rotate: -Math.PI / 2,
								textAlign: 'end',
								textBaseline: 'middle'
							}
						});
						chart.legend(false);
						// 柱状图添加文本
						that.baseData.forEach(function(obj) {
						  chart.guide().text({
						    position: [ obj.date, obj.pointTotal ],
						    content: obj.pointTotal,
						    style: {
						      textAlign: 'center',
						      textBaseline: 'bottom'
						    },
						    offsetY: 0
						  });
						});
						chart.render();
						// 需要把 chart 返回
						return chart;
					})
				}
			
			}
		})
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	//获取今日标签记录列表
	getTodayRecordList(){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getTodayRecordList',
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.recordList = res.data.rows
					} else {
						that.recordList = that.recordList.concat(res.data.rows)
					}
					that.page++
				} else {
					
				}
			}
		})
		
	},
	
	//获取我的全部前置导航
	getMyAllLinks(){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getMyAllLinks',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topLinkList = res.data
				} else {
					
				}
			}
		})
		
	},
	//获取全部导航链接
	getAllLinks(){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllLinks',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.linkList = res.data
				} else {
					
				}
			}
		})
		
	},
	tagLongTap(id,name,isAdd){
		this.currenLinkName = name;
		this.currenLinkId = id;
		this.currenLinkIsTop = isAdd;
		this.$refs.confirmPopup.open();
	},
	tagClick(link){
		window.location.href= link
	},
	close(){
		this.$refs.confirmPopup.close();
	},
	sumbitLinkTop(){
		let that = this
		let url = this.currenLinkIsTop? url="h5/removeUserLink" : url = "h5/addUserLink"
		that.$httpRequest.request({
			that: that,
			url: url,
			params: {
				linkId:that.currenLinkId
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.getMyAllLinks()
					that.getAllLinks()
					
				} else {
					
				}
			}
		})
		this.$refs.confirmPopup.close();
		
	},
	handlerUpload(){
		let that = this;
		//上传照片
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				// console.log(res,"完成上传")
				that.wordList.push(res.data)
				var newlist = that.wordList.map((item,index)=>{
						return item = item.id
					})
				that.formData.picture = newlist.join(',')
				
			}
		});
	},
	toMyTodayData(){
		uni.navigateTo({
			url: '/pages/index/myTodayData'
		})
	},
	//删除照片
	del(index){
		this.wordList.splice(index,1)
		var newlist = this.wordList.map((item,index)=>{
				return item = item.id
			})
		this.formData.picture = newlist.join(',')
	},
	_previewImage(image) {
		var imgArr = [];
		imgArr.push(image);
		//预览图片
		uni.previewImage({
			urls: imgArr,
			current: imgArr[0]
		});
	},
	toScreen(){
		
		
		// //获取网页中的canvas对象  
		let mycans= document.getElementsByTagName("canvas")[0];   
		console.log(mycans)
		// // //调用convertCanvasToImage函数将canvas转化为img形式   
		let img= this.convertCanvasToImage(mycans);  
		console.log(img)
		// //将img插入容器 
		// document.getElementById('screen-box').append(img);
	},
	//从 canvas 提取图片 image  
	convertCanvasToImage(canvas) {  
	    //新Image对象，可以理解为DOM  
	    var image = new Image();  
	    // canvas.toDataURL 返回的是一串Base64编码的URL
	    // 指定格式 PNG  
	    image.src = canvas.toDataURL("image/png");  
	    return image;  
	}
}